<?php

namespace App\Models\Bonus;

use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use App\Models\BaseModel;

class BonusPoolsModel extends BaseModel
{
    protected $table = 'bonus_pools';

    protected $primaryKey = 'id';

    public $dateFormat = 'U';

    protected $dates = [
        'created_at',
        'updated_at',
        'date',
    ];

    protected $guarded = [];

    public function incomeFinance(float $money,$change_type)
    {
        $data['income'] = DB::raw('IFNULL(`income`,0)+'.$money);
        $map['date'] = $data['date'] = Carbon::today()->timestamp;
        $map['change_type'] = $data['change_type'] = $change_type ;
        return self::updateOrInsert($map,$data);
    }

    public function expendFinance(float $money,$change_type)
    {
        $data['expend'] = DB::raw('IFNULL(`expend`,0)+'.$money);
        $map['date'] = $data['date'] = Carbon::today()->timestamp;
        $map['change_type'] = $data['change_type'] = $change_type ;
        return self::updateOrInsert($map,$data);
    }

}
